package com.xhb.biz.service;

import com.baomidou.mybatisplus.solon.service.impl.ServiceImpl;
import com.teamdev.jxbrowser.navigation.event.LoadFinished;
import com.xhb.biz.mapper.HistoryMapper;
import com.xhb.biz.po.History;
import org.noear.solon.aspect.annotation.Service;

import java.util.Date;
import java.util.concurrent.CompletableFuture;

@Service
public class HistoryService extends ServiceImpl<HistoryMapper, History> {

    /**
     * 异步插入
     * @param loadFinished
     */
    public void insertAsync(LoadFinished loadFinished){
        CompletableFuture.runAsync(() -> {
            History history = new History();
            history.setCreateTime(new Date());
            history.setUrl(loadFinished.navigation().browser().url());
            history.setTitle(loadFinished.navigation().browser().title());
            history.setUrlLength(loadFinished.navigation().browser().url().length());
            super.save(history);
        });
    }
}
